#ifndef OBJECTMODEL_H
#define OBJECTMODEL_H

#include <memory>
#include "CommitteeManager.h"
#include "CouncilMemberManager.h"
#include "MembershipHistoryManager.h"
#include "ChairmanshipHistoryManager.h"
#include "SessionManager.h"
#include "SessionPresenceManager.h"
#include "ISerializable.h"

class ObjectModel : public ISerializable
{
  friend class BusinessLogicTest;
public:
  static ObjectModel& instance()
  {
    if (!m_instance.get())
      m_instance.reset(new ObjectModel());
    return *m_instance;
  }

  virtual bool serialize(const std::string& path) const;
  virtual bool deserialize(const std::string& path);

  CommitteeManager& committees() { return *m_committees; }
  CouncilMemberManager& councilMembers() { return *m_councilMembers; }
  MembershipHistoryManager& membershipHistory() { return *m_membershipHistory; }

  ChairmanshipHistoryManager& chairmanshipHistory() {return *m_chairmanshipHistory;}
  SessionManager& sessions() {return *m_sessions;}
  SessionPresenceManager& sessionPresence() {return *m_sessionPresences;}

  void clear();

  virtual ~ObjectModel() {};
private:
  ObjectModel():
    m_committees(new CommitteeManager()),
    m_councilMembers(new CouncilMemberManager()),
    m_membershipHistory(new MembershipHistoryManager()),
	  m_chairmanshipHistory(new ChairmanshipHistoryManager()),
	  m_sessions(new SessionManager()),
	  m_sessionPresences(new SessionPresenceManager())
  {}

  std::auto_ptr<CommitteeManager> m_committees;
  std::auto_ptr<CouncilMemberManager> m_councilMembers;
  std::auto_ptr<MembershipHistoryManager> m_membershipHistory;

  std::auto_ptr<ChairmanshipHistoryManager> m_chairmanshipHistory;
  std::auto_ptr<SessionManager> m_sessions;
  std::auto_ptr<SessionPresenceManager> m_sessionPresences;

  static std::auto_ptr<ObjectModel> m_instance;
};

#endif // OBJECTMODEL_H